home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / MODEMPRO / TVSERIAL.ZIP;1 / SETUP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-24  |  2.8 KB  |  118 lines

  1. //
  2. // SETUP.CPP - code for communication setup dialog box.
  3. //
  4.  
  5. #define Uses_TRadioButtons
  6. #define Uses_TLabel
  7. #define Uses_TButton
  8. #define Uses_TSItem
  9. #define Uses_TView
  10. #define Uses_TRect
  11. #define Uses_TInputLine
  12. #define Uses_TDialog
  13. #define Uses_TEvent
  14. #include <tv.h>
  15.  
  16. #include <ctype.h>
  17. #pragma hdrstop
  18.  
  19. #include "serial.h"
  20. #include "setup.h"
  21.  
  22. class TBitLine : public TInputLine
  23. {
  24.  
  25. public:
  26.  
  27.     TBitLine(TRect& bounds, int aMaxLen, char low = '0', char high = '9') :
  28.         TInputLine(bounds, aMaxLen)
  29.     {
  30.         lowDigit = low; highDigit = high;
  31.     }
  32.     virtual void handleEvent(TEvent& event);
  33.  
  34. private:
  35.  
  36.     char lowDigit, highDigit;
  37.  
  38. };
  39.  
  40. void TBitLine::handleEvent(TEvent& event)
  41. {
  42.     char key = event.keyDown.charScan.charCode;
  43.  
  44.     if( !(event.what == evKeyboard && isprint(key) &&
  45.           (key < lowDigit || key > highDigit)) )
  46.         TInputLine::handleEvent(event);
  47. }
  48.  
  49.  
  50. int comData::getBaud()
  51. {
  52.     switch(baudRate)
  53.     {
  54.     case B300:
  55.         return 300;
  56.     case B1200:
  57.         return 1200;
  58.     case B2400:
  59.         return 2400;
  60.     }
  61.     return 0;       // Useless Baudrate.
  62. }
  63.  
  64. int comData::getParity()
  65. {
  66.     switch(parity)
  67.     {
  68.     case P_EVEN:
  69.         return(EVEN_PARITY);
  70.     case P_ODD:
  71.         return(ODD_PARITY);
  72.     case P_NONE:
  73.         return(NO_PARITY);
  74.     }
  75.     return(-1);     // Invalid parity -- 0 is None so we can't use that.
  76. }
  77.  
  78.  
  79. TSetupDialog::TSetupDialog() :
  80.     TDialog( TRect(0, 0, 43, 14), "Communication Setup" ),
  81.     TWindowInit( initFrame )
  82. {
  83.     TView *control = new TRadioButtons( TRect(3,3,13,6),
  84.                        new TSItem("300",
  85.                        new TSItem("1200",
  86.                        new TSItem("2400", 0)))
  87.                      );
  88.     insert(control);
  89.     insert( new TLabel( TRect(3,2,13,3),"~B~aud Rate", control) );
  90.  
  91.     control = new TRadioButtons( TRect(16,3,27,5),
  92.                 new TSItem("COM 1",
  93.                 new TSItem("COM 2",0))
  94.               );
  95.     insert(control);
  96.     insert( new TLabel( TRect(16,2,21,3), "~P~ort", control) );
  97.  
  98.     control = new TRadioButtons( TRect(30,3,40,6),
  99.                 new TSItem("Even",
  100.                 new TSItem("Odd",
  101.                 new TSItem("None",0)))
  102.               );
  103.     insert(control);
  104.     insert( new TLabel( TRect(31,2,38,3), "P~a~rity", control) );
  105.  
  106.     control = new TBitLine( TRect(15,8,19,9), 2, '0', '2');
  107.     insert(control);
  108.     insert( new TLabel( TRect(3,8,14,9), "~S~top Bits:", control) );
  109.  
  110.     control = new TBitLine( TRect(15,10,19,11), 2, '5', '8');
  111.     insert(control);
  112.     insert( new TLabel( TRect(3,10,14,11), "~D~ata Bits:", control) );
  113.  
  114.     insert( new TButton( TRect(24,8,34,10), "~O~K", cmOK, bfDefault) );
  115.     insert( new TButton( TRect(24,11,34,13), "~C~ancel", cmCancel, bfNormal) );
  116.     selectNext( False );
  117. }
  118.